# !/usr/local/bin/ruby -w 
# filterclass.rb
#
# This Program parses the raw tcpdump data to the 
# format that can be inserted to the Database
# 
# Authors:: Bhushan Kotnis, Akshay Jog (mailto: {bkotnis,akshayj}@eden.rutgers.edu )
# License:: Distributes under the same terms as Ruby
#
# This class has method parse () to parse the tcpdump file into various fileds such time stamp, sender,receiver MAC and 
# IP address  channel number


class Packet
#Various Fileds to be stored into the databse	
def initialize()

@timestamp = "00:00:00"
@sendermac="00:00:00:00:00:00"
@receivermac="00:00:00:00:00"
@senderip="000.000.000.000"
@receiverip="000.000.000.000"


 end
# parse is the method used to parse the raw sniffed data partially
	def parse()
# raw_tcp_dump.txt file has raw information about the sniffed data
		file=File.open("raw_tcp_dump.txt","r") 

#filtered.txt is intermediate file used for parsing the raw data 
		fout=File.open("filtered.txt","w")

while @line=file.gets
if /\d\d:\d\d:\d\d/
# Above is the pattern to parse all time stamps
	@string1 = @line.scan(/\d\d:\d\d:\d\d/)
	fout.puts @string1 
	
end
if /\w\w:\w\w:\w\w:\w\w:\w\w:\w\w/
# Above is the pattern to parse the MAC address
	@string2= @line.scan(/\w\w:\w\w:\w\w:\w\w:\w\w:\w\w/ )


fout.puts @string2


end

if /\d\d\d.\d\d\d.*.*\d./
#Above is the pattern for parsing the IP address
@string = @line.scan(/\d\d\d.\d\d\d.*.*\d. /)

fout.puts @string


end
 fout.puts "\n"
end
file.close
fout.close

end
 
 end
# object packet is created of the class Packet
 packet=Packet.new()

#method call for to parse the raw data
 packet.parse

 